package com.example.transformpage.View;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baselibrary.libs.Utils.UtilsMyText.UtilsMyText;
import com.baselibrary.libs.Utils.log.LogUtils;
import com.example.transformpage.R;

/**
 * Created by Administrator 于萌萌
 * 创建日期: 10:34 . 2017年01月10日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */

public class PlanButton1 extends RelativeLayout implements View.OnClickListener {

    private View mView;
    private TextView plan_button1_title;
    private TextView plan_button1_id;
    private TextView plan_button1_hint1;
    private TextView plan_button1_hint2;
    private TextView plan_button1_hint3;
    private View plan_button1_view1;
    private TextView plan_button1_hint4;
    private TextView plan_button1_hint5;
    private TextView plan_button1_hint6;
    private TextView plan_button1_tv1;
    private TextView plan_button1_tv2;
    private TextView plan_button1_tv3;
    private TextView plan_button1_tv4;
    private TextView plan_button1_tv5;
    private TextView plan_button1_tv6;
    private RelativeLayout plan_button1_retop;
    private View plan_button1_view2;
    private RelativeLayout plan_button1;
    private ImageView plan_button1_iv1;
    private RelativeLayout plan_info;
    private RelativeLayout plan_info1;
    private RelativeLayout plan_info2;
    private RelativeLayout plan_info3;
    private TextView plan_sub;
    private ProgressBar mProgressBar2;

    public int getItemId() {
        return itemId;
    }

    public PlanButton1 setItemId(int itemId) {
        this.itemId = itemId;
        return this;
    }

    private int itemId = 0;

    public PlanButton1(Context context) {
        super(context);
        initView(context);
    }

    public PlanButton1(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public PlanButton1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }



    @Override
    public void onClick(View v) {
        if (null == callBack) {
            return;
        }
        switch (v.getId()) {
            case R.id.plan_info1:
                callBack.plan_info_1_CallBack(plan_info1);
                break;
            case R.id.plan_info2:
                callBack.plan_info_2_CallBack(plan_info2);
                break;
            case R.id.plan_info3:
                callBack.plan_info_3_CallBack(plan_info3);
                break;
        }
    }

    public CallBack callBack;

    public interface CallBack {
        void plan_info_1_CallBack(RelativeLayout plan_info_1);

        void plan_info_2_CallBack(RelativeLayout plan_info_2);

        void plan_info_3_CallBack(RelativeLayout plan_info_3);
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    private void initView(Context context) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.plan_button1, this);
        //计划标题
        plan_button1_title = (TextView) mView.findViewById(R.id.plan_button1_title);
        //编号
        plan_button1_id = (TextView) mView.findViewById(R.id.plan_button1_id);
        //年化利率
        plan_button1_tv1 = (TextView) mView.findViewById(R.id.plan_button1_tv1);
        //投资期限
        plan_button1_tv2 = (TextView) mView.findViewById(R.id.plan_button1_tv2);
        //标的金额
        plan_button1_tv3 = (TextView) mView.findViewById(R.id.plan_button1_tv3);
        //标的倒计时
        plan_button1_tv4 = (TextView) mView.findViewById(R.id.plan_button1_tv4);
        plan_button1_hint4 = (TextView) mView.findViewById(R.id.plan_button1_hint4);
        //剩余可投金额
        plan_button1_tv5 = (TextView) mView.findViewById(R.id.plan_button1_tv5);
        //项目进度
        plan_button1_tv6 = (TextView) mView.findViewById(R.id.plan_button1_tv6);
        //标的状态(图片)
        plan_button1_iv1 = (ImageView) mView.findViewById(R.id.plan_button1_iv1);
        //下面的第一个页面不显示值有在详情才显示
        plan_info = (RelativeLayout) mView.findViewById(R.id.plan_info);
        //下面的第一个页面不显示值有在详情才显示  1
        plan_info1 = (RelativeLayout) mView.findViewById(R.id.plan_info1);
        //下面的第一个页面不显示值有在详情才显示  2
        plan_info2 = (RelativeLayout) mView.findViewById(R.id.plan_info2);
        //下面的第一个页面不显示值有在详情才显示  3
        plan_info3 = (RelativeLayout) mView.findViewById(R.id.plan_info3);
        //进度条
        mProgressBar2 = (ProgressBar)mView.findViewById(R.id.progressBar2);
        mProgressBar2.setMax(100);
        //我要投资
        plan_sub = (TextView) mView.findViewById(R.id.plan_sub);

        plan_sub.setOnClickListener(this);
        plan_info1.setOnClickListener(this);
        plan_info2.setOnClickListener(this);
        plan_info3.setOnClickListener(this);

    }
    public PlanButton1 setData_title(String bid_term){
        String title ="";

        int colorId = R.color.biao_28;
        //根据不同的天数设定不同的颜色 和文字
        if ("28".equals(bid_term)){
            title = "月月享－28天之后收回本息";
            colorId = R.color.biao_28;
        }else if ("56".equals(bid_term)){
            title = "优享计划－每28天返息，到期返本";
            colorId = R.color.biao_56;
        }else if ("84".equals(bid_term)){
            title = "懒人计划－每28天返息，到期返本";
            colorId = R.color.biao_84;
        }else if ("112".equals(bid_term)){
            title = "推荐投资-等额本息";
            colorId = R.color.biao_112;
        }
        plan_button1_title.setText(title);
        plan_button1_title.setBackgroundResource(colorId);
        return this;
    }

//    /**
//     * 设定标题
//     *
//     * @param data_title
//     * @return
//     */
//    public PlanButton1 setData_title(String data_title) {
//        plan_button1_title.setText(data_title);
//        return this;
//    }
    /**
     * 设定按钮是否显示
     *
     * @param sub
     * @return
     */
    public PlanButton1 setData_sub(int sub) {
        if (sub==1){
            plan_sub.setVisibility(VISIBLE);
        }else{

            plan_sub.setVisibility(GONE);
        }
        return this;
    }

    /**
     * 标题是否显示
     * @param b
     * @return
     */
    public PlanButton1 setTitle_Status(boolean b) {
        if (b){
            plan_button1_title.setVisibility(VISIBLE);
        }else{

            plan_button1_title.setVisibility(GONE);
        }
        return this;
    }
    /**
     *  根据传进来的数值 不一样 来进行不同的操作
     * @param status 0 正常标  1 散标
     * @return
     */
    public PlanButton1 setDaojishi_status(int status){
        boolean tag = false;
        if (status ==1){
            tag = false;
        }else{
            tag =true;
        }
        LogUtils.i("我传进来的是"+status+"我干煸的状态是"+tag);
        plan_button1_tv4.setVisibility(tag?GONE:VISIBLE);
        plan_button1_hint4.setVisibility(tag?GONE:VISIBLE);

        return this;
    }

    /**
     * 设定编号
     *
     * @param data_id
     * @return
     */
    public PlanButton1 setData_id(String data_id) {
        plan_button1_id.setText(data_id);
        return this;
    }

    /**
     * 获取条目id 不显示的id
     * @return
     */
    public int getData_id() {
        return getItemId();
    }

    /**
     * 设定年化利率
     *
     * @param data_tv1
     * @return
     */
    public PlanButton1 setData_tv1(String data_tv1) {
        plan_button1_tv1.setText(data_tv1+"%");
        return this;
    }

    /**
     * 设定投资期限
     *
     * @param data_tv2
     * @return
     */
    public PlanButton1 setData_tv2(String data_tv2) {
        plan_button1_tv2.setText(data_tv2+"天");
        return this;
    }

    /**
     * 设定标的金额
     *
     * @param data_tv3
     * @return
     */
    public PlanButton1 setData_tv3(String data_tv3) {
        plan_button1_tv3.setText(data_tv3);
        return this;
    }

    /**
     * 设定标的倒计时
     *
     * @param data_tv4
     * @return
     */
    public PlanButton1 setData_tv4(long data_tv4) {
        String s = UtilsMyText.formatTime(data_tv4);
        plan_button1_tv4.setText(s);
        return this;
    }

    /**
     * 设定剩余可投金额
     *
     * @param data_tv5
     * @return
     */
    public PlanButton1 setData_tv5(String data_tv5) {
        plan_button1_tv5.setText(data_tv5+"元");
        return this;
    }

    /**
     * 设定项目进度
     *
     * @param data_tv6
     * @return
     */
    public PlanButton1 setData_tv6(int data_tv6) {
        plan_button1_tv6.setText(data_tv6+"%");
        mProgressBar2.setProgress(data_tv6);
        return this;
    }

    /**
     * 设定只有在详情的时候设置 下面的显示
     *
     * @param status
     * @return
     */
    public PlanButton1 setItemStuats(int status) {
        if (status == 0) {
            plan_info.setVisibility(GONE);
        } else {
            plan_info.setVisibility(VISIBLE);
        }
        return this;
    }

//    /**
//     * 设定标的状态
//     *
//     * @param status
//     * @return
//     */
//    public PlanButton1 setData_iconStatus(int status) {
//        switch (status) {
//            case 1:
//                plan_button1_iv1.setBackgroundResource(R.drawable.item_01);
//                break;
//            case 2:
//                plan_button1_iv1.setBackgroundResource(R.drawable.item_02);
//                break;
//            case 3:
//                plan_button1_iv1.setBackgroundResource(R.drawable.item_03);
//                break;
//            case 4:
//                plan_button1_iv1.setBackgroundResource(R.drawable.item_04);
//                break;
//        }
//        return this;
//    }


}
